1.0 Look for all files inside the Water Chemistry folder of the ā06. MOATs replication verificationā folder
#*********************************
## 1.) Set working directory
#*********************************
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir =
"/Users/katherinerovinski/GIT/NWFSC.MUK_KRL_SMR2019_waterchemistry")Inside the working directory (folder) is 1 CSV files generated after combining 13CSV logs representing 24second observations. These CSV files were created using the moats graph app
Link to moats.Graph.app Moving average window (nObs) set to 4.
Every 17th observations was selected, the observations were 24second apart.
1 CSVs per moats: M01, M02, M03, M04, M05, M06, M07, M08, M09, M10, M11, M12, M13. Files are also available on the OA Google drive. OA Drive for MOATS data
For speed and ease of computations the dataframe was extermely subsampled. Instead of the standard ān17ā used in the aquarium temperature investigation, this document subsampled at ān333ā.
All observations (per the 13 MOATS logs) [1] 1137880 7 (6 seconds) Number of observations after subsampling every 17th response/observation [1] 66934 7 (24 seconds) Number of observations after the super-subsampling, every 333rd observation [1] 3417 7 (~30minutes) ***this wonāt detail the ramp
To examine the Day to Night ramp (D2Nramp) researcher used n17 subsampling group
#*********************************
## 2. Calling & Reading in " dml "
#*********************************
# Super Speedy subsampled data
dml <- read.csv(file = "M01thruM13moatslog_n17.csv", stringsAsFactors = FALSE)
dim(dml)## [1] 66934 7
#*********************************
## 2.2 Brining in In-Situ
#*********************************
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir =
"/Users/katherinerovinski/GIT/NWFSC.MUK_KRL_SMR2019_waterchemistry")
d.temp.insitu <- read.csv(file = "KRL19_insitu_sample_aTemperature_Day.csv", stringsAsFactors = FALSE)
n.temp.insitu <- read.csv(file = "KRL19_insitu_sample_aTemperature_Night.csv", stringsAsFactors = FALSE)
d.DO.insitu <- read.csv(file = "DO.PreSens.Krill.Day.csv", stringsAsFactors = FALSE)
n.DO.insitu <- read.csv(file = "DO.PreSens.Krill.Night.csv", stringsAsFactors = FALSE)
dn.DO.insitu <- read.csv(file = "DO.PreSens.Krill.DayNight.csv", stringsAsFactors = FALSE)
spec.insitu <- read.csv(file = "2020.10.26a_SpecData.csv", stringsAsFactors = FALSE)Changing MOATs to Factors for the 13 different MOATs- these will be the discrete units for follow analysis
#*********************************
## 3. Reformatting variables/vectors (Factors)
#*********************************
## 3.3 Changing variables |
dml$moats <- factor(dml$moats)
# Checking the names of the different levels
levels(dml$moats)## [1] "M01" "M02" "M03" "M04" "M05" "M06" "M07" "M08" "M09" "M10" "M11" "M12"
## [13] "M13"
## [1] 66934 7
Changes to the format of dates and times for observations
#*********************************
## 4.) Creating dateTime objects
#*********************************
# 4.0 establish the date time object of the CSV |
dml$dateTime <- as.POSIXct(dml$dateTime, format="%Y-%m-%d %H:%M:%OS")
ReferenceTime <- as.POSIXct("2019-09-20 23:59:00")
class(ReferenceTime)## [1] "POSIXct" "POSIXt"
## [1] 66934 7
Three treatments of this studies are identified as * ācurrentā for the Current Conditions Treatment * āhightemperatureā for the High Temperature Conditions Treatment * āallchangeā for the All Change Conditions Treatment which incorporated both the high temperature conditions of the āhightemperatureā treatment along with exposure to lower aquarium pH.
#*********************************
## 5.) Creating Treatment Variables
#*********************************
## 5.1 Identifying treatments by moats
## establishing treatments
dml$treatment <- ""
dml$treatment[dml$moats == "M07" | dml$moats== "M10" | dml$moats== "M12"] <- "current"
dml$treatment[dml$moats == "M01"| dml$moats== "M06"] <- "hightemperature"
dml$treatment[dml$moats == "M02"| dml$moats== "M08" | dml$moats== "M13"] <- "allchange"
dml$treatment[dml$moats == "M03"| dml$moats == "M04" | dml$moats == "M05" | dml$moats== "M11"] <- "broken_and_ambientbroken"
#verify that this new column has been created
names(dml)## [1] "moats" "dateTime" "aTemperature" "sTemperature" "pH"
## [6] "DO" "salinity" "treatment"
#results should include:
#[1] "moats" "dateTime" "aTemperature" "sTemperature" "pH"
#[6] "DO" "salinity" "treatment"
# QA check
dim(dml)## [1] 66934 8
Those MOATS aquarium systems that did not reach desired/programed conditions were deemed the āambientā treatment. No temperature, DO, or pH conditions were programmed or alarmed. Flow control was governed by a solenoid valve to acheive flow/no-flow, day/night periods.
MOATS inside the āAmbientā treatment included MOATs 04 and MOATs 05 both were shown to have faulty thermisters. Recorded conditions of what the animals experienced canāt be guaranteed/confirmed. Without a record of aquarium settings MOATs 04 and MOAT 05 data was not included.
Creating a day and night variables Day and night periods will only refer to time under treatment as a way to exclude the acclimation period. Day and night changed at about ~ 1230 on 05OCT19 Treatment start date considered to begin Monday 23SEP19 at 1200pm Krill Night Starts 1200 (~1230) and ends 2100 Krill Days Starts 2101 and ends 1159 (~1229) Interval 1 start 1200 23SEP19, end 1229 05OCT19 Interval 2 start 1230 05OCT19, end 2100 30OCT19
Interval 1 Interval Date Start ā2019-09-23ā Interval Date End ā2019-10-05ā Day Start Time ā21:01:00ā Day End Time ā11:29:00ā Night Start Time ā12:00:00ā Night End Time ā21:00:00ā DaytoNight Ramp(D2N) ā11:30:00ā start DaytoNight Ramp(D2N) ā11:59:00ā stop Other Time
Interval 2 Interval Date Start ā2019-10-05ā Interval Date End ā2019-10-30ā Day Start Time ā21:01:00ā Day End Time ā12:29:00ā Night Start Time ā12:30:00ā Night End Time ā21:00:00ā Other Time
## 6.5 Day / Night Assignments
# Using the "case_when" function in the tidyverse in the place of a loop
dml <- dml %>% mutate(period=case_when(
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& (ObservationTime >= "12:00:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& (ObservationTime >= "12:31:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <="11:29:00")) ~"day",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <= "12:01:00")) ~"day",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "11:30:00")
| (ObservationTime <="12:00:00")) ~"D2Nramp",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "12:01:00")
| (ObservationTime <= "12:30:00")) ~"D2Nramp",
TRUE ~"other"
)
) #Quick check to see if periods were created
period.intervals <- ggplot(dml, aes(x=dateTime, y=aTemperature)) +
geom_point(aes(colour=period, point=)) +
ggtitle("aTemperature Time Series Plots to Invesitgate Different Intervals") +
ylim (5.0, 15.00)
period.intervals## Warning: Removed 1471 rows containing missing values (geom_point).
The ramp verification will be important to dissolved oxygen verification Dissolved oxygen not yet shown. Recorded dissolved oxygen needs to be corrected with observed salinity. The following 2 plots are only present to visualize the different periods across treatments
ggplot(subset(dml,
period %in% ("D2Nramp")),
aes(x=dateTime, y=aTemperature)) +
geom_point(aes(colour=treatment, point=)) +
ylim (5.0, 15.00) +
ggtitle("aTemperature Values, All MOATs, During Day to Night Ramp Period")## Warning: Removed 26 rows containing missing values (geom_point).
Cdml <- dml %>% filter(!moats %in% c("M03", "M04", "M05", "M11")) %>%
filter(aTemperature>= 5 & aTemperature<=30) %>%
filter(treatment %in% c("current", "allchange", "hightemperature")) %>%
filter(period != "other")Creating the Water Chemistry Dataframe. Differences between dataframes outlined in the graphic below: #### Water Chemistry Dataframe Created āH2Ochemdfā
The acclimation and the time after animals were removed from the system was designated other
Notes from the 2020.05.29 office hours creating 4 new variables in Water Chemistry Dataframe create a vector 181845 for the large n17 file create a vector 9283 observations long for the sub-sub sample n333 file logical vectors- boolean answers to those three below conditions 1 - the measurement per moats per day - MOATs and Data are both available 2 - the measurement (averaged across moats) - group by / summarize tools 3- (data gapped situation- no value matches) take the previous daily average based on observation - lag? previous line on a dataframe ⦠dplyr tool ⦠https://dplyr.tidyverse.org/reference/lead-lag.html 4 - āthe winning valueā case_when #corrected conductivity value
# 8.1 Plots (timeseries verification)
p <- ggplot(H2Ochemdf, aes(x=ObservationDate, y=salinity))+
geom_line() +
ylim (30.05, 27.00)
pggplot(subset(H2Ochemdf,
period %in% ("night")),
aes(x=ObservationDate, y=salinity)) +
geom_point(aes(colour=period, point=)) +
ggtitle("Salinity Constants all Treatments, All MOATs, During Night Period")ggplot(subset(H2Ochemdf,
period %in% ("night")),
aes(x=ObservationDate, y=salinity)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Constants all Treatments, All MOATs, During Night Period")ggplot(subset(H2Ochemdf[H2Ochemdf$moats == "M01", ],
period %in% ("day")),
aes(x=dateTime, y=salinity)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Constant, MOATs 01, During Night Period")These observations consist of salinity measurements taken per MOATS per day. The observation were recorded per MOATS per day as the researcher took point measurements from the aquarium box while doing DO measurements.
Manual records sometimes have holes Monday through Friday averages were recorded with greater fidelity than weekend averages.
DO point measurements occured weekly. Salinity averages were typically recorded every day, Monday- Friday. Some DO measurements were a week apart. The previous daily average was thought to be a better reflection than the last per Day, per MOATs salinity measurement.
(Description) Generic function for replacing each NA with the most recent non-NA prior to it. This function was used to cover those gaps that occured most weekends.
Before the start of the study, a salinity of 28.8PSU was observed the week prior to the studyās start
cycling between different salinity measurements required moving between character based and numeric based functions.
# 8.6a Review of Vectors
# Review of the three different salinity values
# H2Ochemdf$PSUperMOATs measurement
# PSUperMOATs per MOATS per Day
## PSUperMOATs
# H2Ochemdf$PSUprevObs Daily Average
# PSUavgDaily measurment across MOATs
## PSUavgDaily
# H2Ochemdf$PSUprevObs Previous Daily
# PSUprevObs Average to cover those gaps
## PSUprevObs
# Sailinity Assumption 28.8
# Dates w/o Dates without measurement 23~30SEP20
28.8## [1] 28.8
# Final Salinity
H2Ochemdf$Final_PSU <- 0.0
# H2Ochemdf$PSUperMOATs <- ""
# H2Ochemdf$PSUavgDaily <- ""
# H2Ochemdf$PSUprevObs <- ""
# H2Ochemdf$assumed_PSU <- ""
H2Ochemdf$Final_PSU <- as.numeric(case_when(
H2Ochemdf$PSUperMOATs != 'NA' ~ H2Ochemdf$PSUperMOATs,
H2Ochemdf$PSUavgDaily != 'NA' ~ H2Ochemdf$PSUavgDaily,
H2Ochemdf$PSUprevObs != 'NA' ~ H2Ochemdf$PSUprevObs,
TRUE ~ as.character(H2Ochemdf$assumed_PSU),
))FinalSalinity.by.Day <- ggplot(H2Ochemdf,
aes(x=ObservationDate, y=Final_PSU))+
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Values, all MOATS (Daily Value)")
FinalSalinity.by.Dayplot8.8 <- ggplot(subset(H2Ochemdf,
treatment %in% ("allchange")),
aes(x=ObservationDate, y=Final_PSU)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Variation Across All Change Treatment Replicates")
plot8.8plot8.9 <- ggplot(subset(H2Ochemdf,
treatment %in% ("hightemperature")),
aes(x=ObservationDate, y=Final_PSU)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Variation Across High Temperature Conditions Treatment Replicates")
plot8.9The Library wql is required for the following chunk The package name stands for ``water qualityāā and reflects the # original focus on time series data for physical and chemical # properties of water, as well as the biota. Intended for # programs that sample approximately monthly, quarterly or # annually at discrete stations, a feature of many legacy data # sets. Most of the functions should be useful for analysis of # similar-frequency time series regardless of the subject # matter.
#assumption with the 28.8 standard salinity reading
H2Ochemdf$percentDOassumpt <- ""
H2Ochemdf$percentDOassumpt <- as.numeric(H2Ochemdf$percentDOassumpt)
H2Ochemdf$assumedSatDOmg <- ""
H2Ochemdf$assumedSatDOmg <- as.numeric(H2Ochemdf$assumedSatDOmg)
# the percent DO
H2Ochemdf$percentDO <- ""
H2Ochemdf$percentDO <- as.numeric(H2Ochemdf$percentDO)
# Observed / Measured Salinity readings informed answers
H2Ochemdf$obseveredSatDOmg <- ""
H2Ochemdf$obseveredSatDOmg <- as.numeric(H2Ochemdf$obseveredSatDOmg)
H2Ochemdf$actualDOmg <- ""
H2Ochemdf$actualDOmg <- as.numeric(H2Ochemdf$actualDOmg)
# Review of Values
# H2Ochemdf$percentDOassumpt
# H2Ochemdf$assumedSatDOmg
# H2Ochemdf$percentDO
# H2Ochemdf$obseveredSatDOmg
# H2Ochemdf$actualDOmg# saturated mg/L DO at obseved temperature and assumed salinity
# the oxySol() function is form the wql package
H2Ochemdf$assumedSatDOmg <- oxySol(H2Ochemdf$sTemperature,
H2Ochemdf$assumed_PSU)
SatDOplot <- ggplot(H2Ochemdf, aes(x=ObservationDate,
y=assumedSatDOmg))+
geom_point(aes(colour=treatment, point=)) +
ggtitle("Assumed Saturation of Dissolved Oxygen Across all MOATS")
SatDOplot# Back calculated fraction DO as reported by the oxygen sensor
H2Ochemdf$percentDOassumpt <- ""
H2Ochemdf$percentDOassumpt <- as.numeric(H2Ochemdf$percentDOassumpt)
H2Ochemdf$percentDOassumpt <- H2Ochemdf$DO / H2Ochemdf$assumedSatDOmg
p5 <- ggplot(H2Ochemdf, aes(x=dateTime, y=percentDOassumpt)) +
geom_point(aes(colour=period, point=)) +
ggtitle("Assumed Percent DO (All Treatments & All MOATs) Colored by Period")
p5f.H2Ochemdf.ramp = filter(H2Ochemdf,
!moats %in% c('M03', "M04", "M05", "M11") &
treatment %in% c("current", "allchange", "hightemperature") &
period != "night")
f.H2Ochemdf.ramp$moats <- droplevels(f.H2Ochemdf.ramp$moats)
f.H2Ochemdf.ramp$treatment <- factor(f.H2Ochemdf.ramp$treatment)
p5 <- ggplot(f.H2Ochemdf.ramp, aes(x=dateTime, y=percentDOassumpt)) +
geom_point(aes(colour=period, point=)) +
facet_wrap(~treatment)
ggtitle("Assumed Percent DO (All Treatments & All MOATs) Ramping Up From Day to Night")## $title
## [1] "Assumed Percent DO (All Treatments & All MOATs) Ramping Up From Day to Night"
##
## attr(,"class")
## [1] "labels"
#*********************************
## 9.5) Creating Percent Dissoved Oxy Value - Observed Saturated DOmg (measured salinity)
#*********************************
# #satured mg/L at observed temperature and observed (not assumed) salinity
H2Ochemdf$sTemperature <- as.numeric(H2Ochemdf$sTemperature)
H2Ochemdf$obseveredSatDOmg <- oxySol(H2Ochemdf$sTemperature, H2Ochemdf$Final_PSU)#*********************************
## 9.6) Creating Percent Dissoved Oxy Value - Observed/Actual DO (in mg) Saturated DOmg (measured salinity)
#*********************************
# actual DO mg at observed temperature and salinity
H2Ochemdf$percentDO <- H2Ochemdf$DO / H2Ochemdf$assumedSatDOmg
H2Ochemdf$actualDOmg <- H2Ochemdf$percentDO * H2Ochemdf$obseveredSatDOmg
actualDOmgPLOT <- ggplot(H2Ochemdf, aes(x=dateTime, y=H2Ochemdf$actualDOmg)) +
geom_point(aes(colour=period, point=)) +
ggtitle("Actual DO (mg/L) (All Treatments & All MOATs) Colored by Period")
actualDOmgPLOT## Warning: Use of `H2Ochemdf$actualDOmg` is discouraged. Use `actualDOmg` instead.
## Warning: Removed 34 rows containing missing values (geom_point).
# # 10.0) Filtering Data
H2Ochemdf <- H2Ochemdf %>% filter(!moats %in% c("M03", "M04", "M05", "M11")) %>%
filter(sTemperature>= 5 & sTemperature<=30) %>%
filter(treatment %in% c("current", "allchange", "hightemperature")) %>%
filter(period != "other")
write.csv(H2Ochemdf, "2020.10.15_H2Ochemdf.csv")#*********************************
## 10.1) Filtering Data-
#*********************************
filteredFrame = filter(H2Ochemdf,
!moats %in% c('M03', "M04", "M05", "M11") &
(aTemperature>= 5 & aTemperature<=30) &
treatment %in% c("current", "allchange", "hightemperature") &
period != "other")
d.temp.insitu = filter(d.temp.insitu,
!moats %in% c('M03', "M04", "M05", "M11") &
(aTemperature>= 5 & aTemperature<=30) &
treatment %in% c("current", "allchange", "hightemperature") &
period != "other")
n.temp.insitu = filter(n.temp.insitu,
!moats %in% c('M03', "M04", "M05", "M11") &
(aTemperature>= 5 & aTemperature<=30) &
treatment %in% c("current", "allchange", "hightemperature") &
period != "other")
class(ReferenceTime)## [1] "POSIXct" "POSIXt"
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
## 10.1a Dropping levels and factors
filteredFrame$moats <- droplevels(filteredFrame$moats)
filteredFrame$treatment <- factor(filteredFrame$treatment)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
##10.1b Summary Table for Aquarium Temperature if further needed for water chemistry statistics
Cdml.daynight.aTemp.summary <- Cdml %>% group_by(treatment, period) %>%
summarize(sd = sd(aTemperature, na.rm = TRUE),
mean = mean(aTemperature, na.rm = TRUE),
median = median(aTemperature, na.rm = TRUE),
IQR = IQR(aTemperature, na.rm = TRUE),
n = n()) %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)## `summarise()` regrouping output by 'treatment' (override with `.groups` argument)
#10.2a Creating values for date and time to be applied for period
dn.DO.insitu$ObservationDate <- ""
dn.DO.insitu$ObservationTime <- ""
dn.DO.insitu$dateTime<- ""
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#10.2b Create dateTime objects
dn.DO.insitu$dateTime <- as.POSIXct(sprintf("%s %s", dn.DO.insitu$Date, dn.DO.insitu$Time), format="%m/%d/%y %H:%M")
dn.DO.insitu$ObservationDate <- as.Date(dn.DO.insitu$dateTime)
dn.DO.insitu$ObservationTime <- format(as.POSIXct(dn.DO.insitu$dateTime) ,format = "%H:%M:%S")
dn.DO.insitu <- filter(dn.DO.insitu,
!MOATS %in% c('3', "4", "5", "11") &
treatment %in% c("current", "allchange", "hightemperature") &
!treatment %in% c("Ambient"))
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#10.2bc Creating period with same argument as appiled to dml/Cdml/ and H2Ochemdf
dn.DO.insitu$period <-""
dn.DO.insitu <- dn.DO.insitu %>% mutate(period=case_when(
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& (ObservationTime >= "12:00:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& (ObservationTime >= "12:31:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <="11:29:00")) ~"day",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <= "12:01:00")) ~"day",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "11:30:00")
| (ObservationTime <="12:00:00")) ~"D2Nramp",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "12:01:00")
| (ObservationTime <= "12:30:00")) ~"D2Nramp",
TRUE ~"other"
)
)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# d.DO.insitu = filter(d.DO.insitu,
# !MOATS %in% c('3', "4", "5", "11") &
# treatment %in% c("current", "allchange", "hightemperature"))
#
# d.DO.insitu$dateTime <- as.POSIXct(sprintf("%s %s", d.DO.insitu$Date, d.DO.insitu$Time), format="%m/%d/%y %H:%M")
#
#
# n.DO.insitu = filter(n.DO.insitu,
# !MOATS %in% c('3', "4", "5", "11") &
# treatment %in% c("current", "allchange", "hightemperature") &
# !treatment %in% c("Ambient"))
#
# n.DO.insitu$dateTime <- as.POSIXct(sprintf("%s %s", n.DO.insitu$Date, n.DO.insitu$Time), format="%m/%d/%y %H:%M")# dim(d.DO.insitu)
# dim(n.DO.insitu)
#
# DO.insitu <- merge(d.DO.insitu, n.DO.insitu,by="dateTime")
#
#
# DO.insitu.1 <- merge(d.DO.insitu, n.DO.insitu, by = "dateTime", all = TRUE)
#
# #DO.insitu.2 <- merge(d.DO.insitu, n.DO.insitu, by.x = "dateTime", by.y = "Date").
# #DOinsitu.3 <- rbind(d.DO.insitu, n.DO.insitu)## [1] 413 24
spec.insitu$treatment <- ""
spec.insitu$treatment[spec.insitu$unit_number == "7" | spec.insitu$unit_number== "10" | spec.insitu$unit_number== "12"] <- "current"
spec.insitu$treatment[spec.insitu$unit_number == "1"| spec.insitu$unit_number== "6"] <- "hightemperature"
spec.insitu$treatment[spec.insitu$unit_number == "2"| spec.insitu$unit_number== "8" | spec.insitu$unit_number== "13"] <- "allchange"
spec.insitu$treatment[spec.insitu$unit_number == "3"| spec.insitu$unit_number == "4" | spec.insitu$unit_number == "5" | spec.insitu$unit_number== "11"] <- "broken_and_ambientbroken"
# filtering out broken and ambient MOATs
spec.insitu = filter(spec.insitu,
!unit_number %in% c('3', "4", "5", "11"))
# creating observation Dates and observation time to create period simular to existing system data set
spec.insitu$ObservationDate <- ""
spec.insitu$ObservationTime <- ""
# converting time from a fraction of the day by seconds to regular time
# Extracting Hours
spec.insitu$hours <- ""
spec.insitu$hours <- (round(spec.insitu$HoursFromMID, digits = 0))
# Extracting Minutes
spec.insitu$minutes <- ""
spec.insitu$minutes <- (spec.insitu$HoursFromMID %% 1)*60
spec.insitu$minutes <- (round(spec.insitu$minutes, digits = 0))
# Creating a character string seperated by semicolon for hours and minutes
minChar <- as.character(spec.insitu$minutes)
hrChar <- as.character(spec.insitu$hours)
spec.insitu$timeChar <- ""
spec.insitu$timeChar <- paste(hrChar, minChar, sep=":")
#Creating a date time for SPEC measurements
spec.insitu$dateTime <- ""
spec.insitu$dateTime <- as.POSIXct(paste(spec.insitu$date,
spec.insitu$timeChar), "%m/%d/%y %H:%M", tz="UTC")
spec.insitu$ObservationDate <- as.Date(spec.insitu$dateTime)
spec.insitu$ObservationTime <- format(as.POSIXct(spec.insitu$dateTime) ,format = "%H:%M")
spec.insitu$period <-""
spec.insitu <- spec.insitu %>% mutate(period=case_when(
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& (ObservationTime >= "12:00:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& (ObservationTime >= "12:31:00")
& (ObservationTime <="21:00:00") ~"night",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <="11:29:00")) ~"day",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "21:01:00")
| (ObservationTime <= "12:01:00")) ~"day",
(ObservationDate >= "2019-09-23")
& (ObservationDate <="2019-10-05")
& ((ObservationTime >= "11:30:00")
| (ObservationTime <="12:00:00")) ~"D2Nramp",
(ObservationDate >= "2019-10-05")
& (ObservationDate <= "2019-10-30")
& ((ObservationTime >= "12:01:00")
| (ObservationTime <= "12:30:00")) ~"D2Nramp",
TRUE ~"other"
)
)
spec.insitu <- filter(spec.insitu,
!unit_number %in% c('3', "4", "5", "11") &
treatment %in% c("current", "allchange", "hightemperature") &
period != "other")
# #filteredSPECFrame$unit_number <- droplevels(filteredSPECFrame$unit_number)
# filteredSPECFrame$treatment <- factor(filteredSPECFrame$treatment)## 11.1 DO averages- days and nights
# Creating Values
# Day
allchgDay_DO <- subset(H2Ochemdf,
period == "day" & treatment == "allchange",
select = c(dateTime, actualDOmg))
curDay_DO <- subset(H2Ochemdf,
period == "day" & treatment == "current",
select = c(dateTime, actualDOmg))
hitempDay_DO <- subset(H2Ochemdf,
period == "day" & treatment == "hightemperature",
select = c(dateTime, actualDOmg))# Creating Values
# Night
allchgNightDO <- subset(H2Ochemdf,
period == "night" & treatment == "allchange",
select = c(dateTime, actualDOmg ))
curNightDO <- subset(H2Ochemdf,
period == "night" & treatment == "current",
select = c(dateTime, actualDOmg ))
hitempNightDO <- subset(H2Ochemdf,
period == "night" & treatment == "hightemperature",
select = c(dateTime, actualDOmg ))## [1] 18273 21
H2Ochemdf.daynight.actualDO.summary <- H2Ochemdf %>% group_by(treatment, period) %>%
summarize(sd = sd(actualDOmg, na.rm = TRUE),
mean = mean(actualDOmg, na.rm = TRUE),
median = median(actualDOmg, na.rm = TRUE),
IQR = IQR(actualDOmg, na.rm = TRUE),
n = n(), .groups= "drop_last") %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)
write.csv(H2Ochemdf.daynight.actualDO.summary, "2020.10.15_H2Ochemdf_daynight_actualDO_summary.csv")## [1] 18273 21
H2Ochemdf.daynight.pH.summary <- H2Ochemdf %>% group_by(treatment, period) %>%
summarize(sd = sd(pH, na.rm = TRUE),
mean = mean(pH, na.rm = TRUE),
median = median(pH, na.rm = TRUE),
IQR = IQR(pH, na.rm = TRUE),
n = n(), .groups= "drop_last") %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)
write.csv(H2Ochemdf.daynight.pH.summary, "2020.10.15_H2Ochemdf_daynight_pH_summary.csv") plerts <- ggplot(H2Ochemdf, aes(treatment, actualDOmg)) +
geom_jitter(color = "grey") +
geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
geom_point(data = H2Ochemdf.daynight.actualDO.summary, aes(x=treatment, y=mean), size=5, color = "purple") +
geom_errorbar(data =H2Ochemdf.daynight.actualDO.summary,
aes(x=treatment, y=mean, ymin = mean-sd, ymax = mean+sd),
color = "blue") +
geom_errorbar(data = H2Ochemdf.daynight.actualDO.summary,
aes(x=treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
colour = "red") +
facet_wrap(~period) +
geom_jitter(data = dn.DO.insitu, aes(treatment, actualDOmg),
color = "black") +
facet_wrap(~period) +
ggtitle("All Treatments, Actual Dissolved Oxygen (mg) Across Periods") +
theme_bw()
plerts## Warning: Removed 3 rows containing missing values (geom_point).
ggplot(H2Ochemdf, aes(treatment, pH)) +
geom_jitter(color = "grey") +
geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
geom_point(data = H2Ochemdf.daynight.pH.summary, aes(x=treatment, y=mean), size=5, color = "purple") +
geom_errorbar(data =H2Ochemdf.daynight.pH.summary,
aes(x=treatment, y=mean, ymin = mean-sd, ymax = mean+sd),
color = "blue") +
geom_errorbar(data = H2Ochemdf.daynight.pH.summary,
aes(x=treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
colour = "red") +
geom_jitter(data = spec.insitu, aes(treatment, pH),
color = "black") +
facet_wrap(~period) +
ggtitle("All Treatments, Water Chemistry pH, Across Periods") +
theme_bw()## Warning: Removed 10 rows containing missing values (geom_point).
## [1] 258 32
pH.insitu.daynight.pH.summary <- spec.insitu %>% group_by(treatment, period) %>%
summarize(sd = sd(pH, na.rm = TRUE),
mean = mean(pH, na.rm = TRUE),
median = median(pH, na.rm = TRUE),
IQR = IQR(pH, na.rm = TRUE),
n = n(), .groups= "drop_last") %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)
write.csv(pH.insitu.daynight.pH.summary, "2020.10.26_pH.insitu.daynight.pH.summary.csv")lack of clear day and night might be due to how much change is happening durring the ramp period
ggplot(subset(H2Ochemdf[H2Ochemdf$treatment == "allchange", ],
period %in% ("day")),
aes(x=dateTime, y=pH)) +
geom_point(aes(colour=moats, point=)) +
# geom_violin() +
ylim (6.6, 7.8) The following graphs show dissolved oxygen and pH observations. The goal is to describe the time the system spent at different set points. The empirical cumulative distribution function (ECDF) provides an alternative visualisation of distribution. Compared to other visualizations that rely on density (like geom_histogram()), the ECDF doesnāt require any tuning parameters and handles both continuous and categorical variables.
## 14.1 Histogram plot- all moats, all treatments, all periods
# Cdml %>% ggplot(data=.)+geom_histogram(aes(x=aTemperature), binwidth = .05) +
# xlim(5,30) +
# ylim(0, 10000)Section below walks how to quantify each ābinā by the observation period = 6.8minutes
#find duration of each observations in hours
durObsHours <- 6.8/60
# the count (number of observations in each bin) is scale by time duration of each obs
# option to also include polygon
# could fix the vline to only show the value relevant for each plot
#vline could show acutal mean temperature, not just target
# each bin shows 0.2 degrees
plot13.a_temp <- ggplot(Cdml, aes(aTemperature)) +
geom_histogram(aes(y=..count..*durObsHours),
binwidth = 0.2) +
# geom_freqpoly(aes(y=..count..*durObs)) +
geom_vline(xintercept = c(11,12,13,14), colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
plot13.a_temp## Warning: Removed 26 rows containing missing values (geom_bar).
#find duration of each observations in hours
durObsHours <- 6.8/60
# the count (number of observations in each bin) is scale by time duration of each obs
# option to also include polygon
# could fix the vline to only show the value relevant for each plot
#vline could show acutal mean temperature, not just target
# each bin shows 0.2 degrees
plot13.2c_DO <- ggplot(H2Ochemdf, aes(actualDOmg)) +
geom_histogram(aes(y=..count..*durObsHours),
binwidth = 0.2) +
# geom_freqpoly(aes(y=..count..*durObs)) +
geom_vline(xintercept = c(4,6,8,10), colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
plot13.2c_DOECFDplot <- ggplot(H2Ochemdf, aes(actualDOmg)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = c(4,6,8,10), colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
ECFDplot ECDFplot2 <- ggplot(H2Ochemdf, aes(percentDO)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = c(.6,.7,.8,.9), colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
ECDFplot2ECDFplot13.3c <- ggplot(H2Ochemdf, aes(actualDOmg)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = H2Ochemdf.daynight.actualDO.summary$mean, colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
ECDFplot13.3c## 14.3d ECDF Plot
ECDF_Plot_13.3d <- ggplot(H2Ochemdf, aes(actualDOmg)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = H2Ochemdf.daynight.actualDO.summary$mean, colour = "red") +
facet_wrap(vars(treatment, period), ncol = 2, scales = "fixed") +
theme_bw()
ECDF_Plot_13.3dThe cool ECDF function should incorporate the summary statistics and displacy averages coolECDF- incorporates aquarium temperature summary statisics DOcoolECDF- will incorporate actual mg of dissolved oxygen summary statistics pHcoolECDF- will incorporate pH summary statistics. pH measurements discussed more in chapter 13.
## 13.4 Creating a function to incorporate our statistics- displaying the averages
#*********************************
## Aquarium Temperature Summary Statistics Function
#*********************************
coolECDF <- function(d, dsum, treat, per){
dsum <- dsum %>% filter(treatment == treat & period == per )
p <- d %>% filter(treatment == treat & period == per ) %>% ggplot(aes(aTemperature)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = dsum$mean, colour = "red") +
ggtitle(paste(treat, per)) +
theme_bw()
return(p)
}
#*********************************
## Actual DOmg Summary Statistics Function
#*********************************
DOcoolECDF <- function(d, dsum, treat, per){
dsum <- dsum %>% filter(treatment == treat & period == per )
p <- d %>% filter(treatment == treat & period == per ) %>% ggplot(aes(actualDOmg)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = dsum$mean, colour = "red") +
ggtitle(paste(treat, per)) +
theme_bw()
return(p)
}
#*********************************
## pH Summary Statistics Function
#*********************************
pHcoolECDF <- function(d, dsum, treat, per){
dsum <- dsum %>% filter(treatment == treat & period == per )
p <- d %>% filter(treatment == treat & period == per ) %>% ggplot(aes(pH)) +
stat_ecdf(aes(colour = moats)) +
geom_vline(xintercept = dsum$mean, colour = "red") +
ggtitle(paste(treat, per)) +
theme_bw()
return(p)
}## 14.4a Using the coolECDF function per treatment & period
cfd.a.d <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "allchange", "day")
cfd.a.n <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "allchange", "night")
cfd.c.d <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "current", "day")
cfd.c.n <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "current", "night")
cfd.h.d <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "hightemperature", "day")
cfd.h.n <- coolECDF(Cdml, Cdml.daynight.aTemp.summary, "hightemperature", "night")
## 14.4b Incorporating Grid Arrange to display the ECDF plots
# Basic Grid Arrange
grid.arrange(cfd.a.d, cfd.c.d, cfd.h.d, nrow = 1) #make a list of all the plots then pass the list to grid.arrange()
ecdfList <- list(cfd.a.d, cfd.c.d, cfd.h.d, cfd.a.n, cfd.c.n, cfd.h.n)
grid.arrange(grobs = ecdfList, ncol=3) #*********************************
## DO & COOL ECDF function
#*********************************
## 13.5a Using the coolECDF function per treatment & period for DOmg
# DO.cfd.allchg.d <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "allchange", "day",)
# DO.cfd.allchg.r <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "allchange", "D2Nramp",)
# DO.cfd.allchg.n <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "allchange", "night")
#
#
# DO.cfd.cur.d <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "current", "day")
# DO.cfd.cur.r <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "current", "D2Nramp")
# DO.cfd.cur.n <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "current", "night")
#
#
# DO.cfd.hi.d <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "hightemperature", "day")
# DO.cfd.hi.r <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "hightemperature", "D2Nramp")
# DO.cfd.hi.n <- DOcoolECDF(H2Ochemdf, H2Ochemdf.daynight.actualDO.summary, "hightemperature", "night")
#
#
# ## 14.4b Incorporating Grid Arrange to display the ECDF plots
# # Basic Grid Arrange
# # Note extra period - the ramp period
#
# grid.arrange(DO.cfd.allchg.d , DO.cfd.cur.d, DO.cfd.hi.d, nrow = 1)
#
# grid.arrange(DO.cfd.allchg.r , DO.cfd.cur.r, DO.cfd.hi.r, nrow = 1)
#
# grid.arrange(DO.cfd.allchg.n , DO.cfd.cur.n, DO.cfd.hi.n, nrow = 1)
#
#
# #make a list of all the plots then pass the list to grid.arrange()
# ecdfList <- list(DO.cfd.allchg.d,
# DO.cfd.allchg.r,
# DO.cfd.allchg.n,
#
# DO.cfd.cur.d,
# DO.cfd.cur.r,
# DO.cfd.cur.n,
#
# DO.cfd.hi.d,
# DO.cfd.hi.r,
# DO.cfd.hi.n
# )
# grid.arrange(grobs = ecdfList, ncol=3)
# #*********************************
## pH Water Chemistry & COOL ECDF function
#*********************************
## 14.6a Using the coolECDF function per treatment & period for pH
# pH.cfd.allchg.d <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "allchange", "day",)
# pH.cfd.allchg.r <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "allchange", "D2Nramp",)
# pH.cfd.allchg.n <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "allchange", "night")
#
#
# pH.cfd.cur.d <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "current", "day")
# pH.cfd.cur.r <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "current", "D2Nramp")
# pH.cfd.cur.n <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "current", "night")
#
#
# pH.cfd.hi.d <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "hightemperature", "day")
# pH.cfd.hi.r <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "hightemperature", "D2Nramp")
# pH.cfd.hi.n <- pHcoolECDF(H2Ochemdf, H2Ochemdf.daynight.pH.summary, "hightemperature", "night")
#
#
# ## 14.4b Incorporating Grid Arrange to display the ECDF plots
# # Basic Grid Arrange
# # Note extra period - the ramp period
#
# grid.arrange(pH.cfd.allchg.d , pH.cfd.cur.d, pH.cfd.hi.d, nrow = 1)
#
# grid.arrange(pH.cfd.allchg.r , pH.cfd.cur.r, pH.cfd.hi.r, nrow = 1)
#
# grid.arrange(pH.cfd.allchg.n , pH.cfd.cur.n, pH.cfd.hi.n, nrow = 1)
#
#
# #make a list of all the plots then pass the list to grid.arrange()
# ecdfList <- list(pH.cfd.allchg.d,
# pH.cfd.allchg.r,
# pH.cfd.allchg.n,
#
# pH.cfd.cur.d,
# pH.cfd.cur.r,
# pH.cfd.cur.n,
#
# pH.cfd.hi.d,
# pH.cfd.hi.r,
# pH.cfd.hi.n
# )
# grid.arrange(grobs = ecdfList, ncol=3)
#
# ExecutiveSummary
Creating the Water Chemistry Dataframe. Differences between dataframes outlined in the graphic below:
A mosaic of salinity values were used to update the salinity constants for correct DO measurements. Decision needed to determine if enough variation present to continue with āFinal_PSUā or return to using the salinity constants
FinalSalinity.Daily <- ggplot(H2Ochemdf,
aes(x=ObservationDate, y=Final_PSU))+
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Values, all MOATS (Daily Value)")
FinalSalinity.DailyThe following plots are broken down by treatment to gain more clarity about observed salinity values. ##### A.2.1 Variation in Salinity- All Change Treatment
plotA.2.1 <- ggplot(subset(H2Ochemdf,
treatment %in% ("allchange")),
aes(x=ObservationDate, y=Final_PSU)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Variation Across All Change Treatment Replicates")
plotA.2.1plotA.2.2 <- ggplot(subset(H2Ochemdf,
treatment %in% ("hightemperature")),
aes(x=ObservationDate, y=Final_PSU)) +
geom_point(aes(colour=moats, point=)) +
ggtitle("Salinity Variation Across High Temperature Conditions Treatment Replicates")
plotA.2.2When discussing water chemistry the greatest amount of change would occur during the ramp period. I didnāt want this to affect the systemās summary average for DO or pH, Day and Night respectively. Plot below shows the progression of DO from low Day time set points towards the 100% DO saturation.
A3a <- ggplot(f.H2Ochemdf.ramp, aes(x=dateTime, y=percentDOassumpt)) +
geom_point(aes(colour=period, point=)) +
facet_wrap(~treatment)
ggtitle("Assumed Percent DO (All Treatments & All MOATs) Ramping Up From Day to Night")## $title
## [1] "Assumed Percent DO (All Treatments & All MOATs) Ramping Up From Day to Night"
##
## attr(,"class")
## [1] "labels"
Filtering data focused around throwing out incongruous temperatures and dropping faulty MOATs.
#*********************************
## Filtering Data- Temp
#*********************************
# filteredFrame = filter(H2Ochemdf,
# !moats %in% c('M03', "M04", "M05", "M11") &
# (aTemperature>= 5 & aTemperature<=30) &
# treatment %in% c("current", "allchange", "hightemperature") &
# period != "other")
#
# d.temp.insitu = filter(d.temp.insitu,
# !moats %in% c('M03', "M04", "M05", "M11") &
# (aTemperature>= 5 & aTemperature<=30) &
# treatment %in% c("current", "allchange", "hightemperature") &
# period != "other")
#
# n.temp.insitu = filter(n.temp.insitu,
# !moats %in% c('M03', "M04", "M05", "M11") &
# (aTemperature>= 5 & aTemperature<=30) &
# treatment %in% c("current", "allchange", "hightemperature") &
# period != "other")
#
# class(ReferenceTime)
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# #*********************************
# ## Filtering Data- DO
# #*********************************
#
# #10.2a Creating values for date and time to be applied for period
# dn.DO.insitu$ObservationDate <- ""
# dn.DO.insitu$ObservationTime <- ""
# dn.DO.insitu$dateTime<- ""
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# #10.2b Create dateTime objects
# dn.DO.insitu$dateTime <- as.POSIXct(sprintf("%s %s", dn.DO.insitu$Date, dn.DO.insitu$Time), format="%m/%d/%y %H:%M")
#
# dn.DO.insitu$ObservationDate <- as.Date(dn.DO.insitu$dateTime)
#
# dn.DO.insitu$ObservationTime <- format(as.POSIXct(dn.DO.insitu$dateTime) ,format = "%H:%M:%S")
#
# dn.DO.insitu <- filter(dn.DO.insitu,
# !MOATS %in% c('3', "4", "5", "11") &
# treatment %in% c("current", "allchange", "hightemperature") &
# !treatment %in% c("Ambient"))
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # #10.2bc Creating period with same argument as appiled to dml/Cdml/ and H2Ochemdf
# # dn.DO.insitu$period <-""
# #
# # dn.DO.insitu <- dn.DO.insitu %>% mutate(period=case_when(
# # (ObservationDate >= "2019-09-23")
# # & (ObservationDate <="2019-10-05")
# # & (ObservationTime >= "12:00:00")
# # & (ObservationTime <="21:00:00") ~"night",
# #
# # (ObservationDate >= "2019-10-05")
# # & (ObservationDate <= "2019-10-30")
# # & (ObservationTime >= "12:31:00")
# # & (ObservationTime <="21:00:00") ~"night",
# #
# # (ObservationDate >= "2019-09-23")
# # & (ObservationDate <="2019-10-05")
# # & ((ObservationTime >= "21:01:00")
# # | (ObservationTime <="11:29:00")) ~"day",
# #
# # (ObservationDate >= "2019-10-05")
# # & (ObservationDate <= "2019-10-30")
# # & ((ObservationTime >= "21:01:00")
# # | (ObservationTime <= "12:01:00")) ~"day",
# #
# # (ObservationDate >= "2019-09-23")
# # & (ObservationDate <="2019-10-05")
# # & ((ObservationTime >= "11:30:00")
# # | (ObservationTime <="12:00:00")) ~"D2Nramp",
# #
# # (ObservationDate >= "2019-10-05")
# # & (ObservationDate <= "2019-10-30")
# # & ((ObservationTime >= "12:01:00")
# # | (ObservationTime <= "12:30:00")) ~"D2Nramp",
# #
# #
# # TRUE ~"other"
# # )
# #
# # ) |
# #
# # #*********************************
# # ## Filtering Data- pH
# # #*********************************
# #
# # dim(spec.insitu)
#
# spec.insitu$treatment <- ""
# spec.insitu$treatment[spec.insitu$unit_number == "7" | spec.insitu$unit_number== "10" | spec.insitu$unit_number== "12"] <- "current"
# spec.insitu$treatment[spec.insitu$unit_number == "1"| spec.insitu$unit_number== "6"] <- "hightemperature"
# spec.insitu$treatment[spec.insitu$unit_number == "2"| spec.insitu$unit_number== "8" | spec.insitu$unit_number== "13"] <- "allchange"
# spec.insitu$treatment[spec.insitu$unit_number == "3"| spec.insitu$unit_number == "4" | spec.insitu$unit_number == "5" | spec.insitu$unit_number== "11"] <- "broken_and_ambientbroken"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # filtering out broken and ambient MOATs
# spec.insitu = filter(spec.insitu,
# !unit_number %in% c('3', "4", "5", "11"))
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # creating observation Dates and observation time to create period simular to existing system data set
# spec.insitu$ObservationDate <- ""
# spec.insitu$ObservationTime <- ""
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
# # converting time from a fraction of the day by seconds to regular time
# # Extracting Hours
# spec.insitu$hours <- ""
# spec.insitu$hours <- (round(spec.insitu$HoursFromMID, digits = 0))
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # Extracting Minutes
# spec.insitu$minutes <- ""
# spec.insitu$minutes <- (spec.insitu$HoursFromMID %% 1)*60
# spec.insitu$minutes <- (round(spec.insitu$minutes, digits = 0))
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # Creating a character string seperated by semicolon for hours and minutes
# minChar <- as.character(spec.insitu$minutes)
# hrChar <- as.character(spec.insitu$hours)
# spec.insitu$timeChar <- ""
# spec.insitu$timeChar <- paste(hrChar, minChar, sep=":")
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# #Creating a date time for SPEC measurements
# spec.insitu$dateTime <- ""
# spec.insitu$dateTime <- as.POSIXct(paste(spec.insitu$date,
# spec.insitu$timeChar), "%m/%d/%y %H:%M", tz="UTC")
# spec.insitu$ObservationDate <- as.Date(spec.insitu$dateTime)
# spec.insitu$ObservationTime <- format(as.POSIXct(spec.insitu$dateTime) ,format = "%H:%M")
#
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# # Applying standard period interval argument
# spec.insitu$period <-""
#
# spec.insitu <- spec.insitu %>% mutate(period=case_when(
# (ObservationDate >= "2019-09-23")
# & (ObservationDate <="2019-10-05")
# & (ObservationTime >= "12:00:00")
# & (ObservationTime <="21:00:00") ~"night",
#
# (ObservationDate >= "2019-10-05")
# & (ObservationDate <= "2019-10-30")
# & (ObservationTime >= "12:31:00")
# & (ObservationTime <="21:00:00") ~"night",
#
# (ObservationDate >= "2019-09-23")
# & (ObservationDate <="2019-10-05")
# & ((ObservationTime >= "21:01:00")
# | (ObservationTime <="11:29:00")) ~"day",
#
# (ObservationDate >= "2019-10-05")
# & (ObservationDate <= "2019-10-30")
# & ((ObservationTime >= "21:01:00")
# | (ObservationTime <= "12:01:00")) ~"day",
#
# (ObservationDate >= "2019-09-23")
# & (ObservationDate <="2019-10-05")
# & ((ObservationTime >= "11:30:00")
# | (ObservationTime <="12:00:00")) ~"D2Nramp",
#
# (ObservationDate >= "2019-10-05")
# & (ObservationDate <= "2019-10-30")
# & ((ObservationTime >= "12:01:00")
# | (ObservationTime <= "12:30:00")) ~"D2Nramp",
#
#
# TRUE ~"other"
# )
#
# )
#
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
#
#
# spec.insitu <- filter(spec.insitu,
# !unit_number %in% c('3', "4", "5", "11") &
# treatment %in% c("current", "allchange", "hightemperature") &
# period != "other")
#
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | The following chunks will show the summary tablesā generation and information plotted with boxplots Order: 1. Aquarium Temperatures 2. Dissolved Oxygen 3. pH
##Summary Table for Aquarium Temperature if further needed for water chemistry statistics
Cdml.daynight.aTemp.summary <- Cdml %>% group_by(treatment, period) %>%
summarize(sd = sd(aTemperature, na.rm = TRUE),
mean = mean(aTemperature, na.rm = TRUE),
median = median(aTemperature, na.rm = TRUE),
IQR = IQR(aTemperature, na.rm = TRUE),
n = n()) %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)## `summarise()` regrouping output by 'treatment' (override with `.groups` argument)
write.csv(Cdml.daynight.aTemp.summary, "2020.10.15_Cdml_daynight_aTemp_summary.csv")
kable(Cdml.daynight.aTemp.summary, digits = 2)| treatment | period | sd | mean | median | IQR | n | se | ci |
|---|---|---|---|---|---|---|---|---|
| allchange | D2Nramp | 0.32 | 13.63 | 13.70 | 0.40 | 166 | 0.02 | 0.05 |
| allchange | day | 0.36 | 12.95 | 12.89 | 0.23 | 4802 | 0.01 | 0.01 |
| allchange | night | 0.25 | 13.90 | 13.92 | 0.19 | 2842 | 0.00 | 0.01 |
| current | D2Nramp | 0.43 | 11.76 | 11.96 | 0.54 | 135 | 0.04 | 0.07 |
| current | day | 0.32 | 11.08 | 11.07 | 0.20 | 3849 | 0.01 | 0.01 |
| current | night | 0.30 | 11.95 | 12.05 | 0.12 | 2285 | 0.01 | 0.01 |
| hightemperature | D2Nramp | 0.48 | 13.45 | 13.49 | 0.57 | 86 | 0.05 | 0.10 |
| hightemperature | day | 0.35 | 12.91 | 12.91 | 0.29 | 2607 | 0.01 | 0.01 |
| hightemperature | night | 0.31 | 13.80 | 13.88 | 0.19 | 1501 | 0.01 | 0.02 |
ggplot(Cdml, aes(treatment, aTemperature)) +
geom_jitter(color = "grey") +
# geom_jitter(data = d.temp.insitu, aes(treatment, aTemperature)) +
# geom_jitter(data = n.temp.insitu, aes(treatment, aTemperature)) +
# geom_jitter(aes(colour = black)) +
geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
geom_point(data = Cdml.daynight.aTemp.summary, aes(x=treatment, y=mean), size=5, color = "purple") +
geom_errorbar(data = Cdml.daynight.aTemp.summary,
aes(x=treatment, y=mean, ymin = mean-sd, ymax = mean+sd),
color = "blue") +
geom_errorbar(data = Cdml.daynight.aTemp.summary,
aes(x=treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
colour = "red") +
facet_wrap(~period) +
ggtitle("All Treatments, Aquarium Temperature Summarized") +
theme_bw() ## [1] 18273 21
H2Ochemdf.daynight.actualDO.summary <- H2Ochemdf %>% group_by(treatment, period) %>%
summarize(sd = sd(actualDOmg, na.rm = TRUE),
mean = mean(actualDOmg, na.rm = TRUE),
median = median(actualDOmg, na.rm = TRUE),
IQR = IQR(actualDOmg, na.rm = TRUE),
n = n(), .groups= "drop_last") %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)
write.csv(H2Ochemdf.daynight.actualDO.summary, "2020.10.26_H2Ochemdf_daynight_actualDO_summary.csv")
kable(H2Ochemdf.daynight.actualDO.summary, digits=2)| treatment | period | sd | mean | median | IQR | n | se | ci |
|---|---|---|---|---|---|---|---|---|
| allchange | D2Nramp | 0.70 | 7.55 | 7.62 | 0.90 | 166 | 0.05 | 0.11 |
| allchange | day | 0.90 | 5.01 | 4.71 | 0.82 | 4802 | 0.01 | 0.03 |
| allchange | night | 0.36 | 8.37 | 8.45 | 0.25 | 2842 | 0.01 | 0.01 |
| current | D2Nramp | 0.56 | 8.33 | 8.42 | 0.90 | 135 | 0.05 | 0.09 |
| current | day | 1.06 | 6.08 | 5.67 | 0.90 | 3849 | 0.02 | 0.03 |
| current | night | 0.44 | 8.80 | 8.92 | 0.26 | 2285 | 0.01 | 0.02 |
| hightemperature | D2Nramp | 0.50 | 8.19 | 8.28 | 0.70 | 86 | 0.05 | 0.11 |
| hightemperature | day | 0.82 | 5.66 | 5.51 | 0.62 | 2607 | 0.02 | 0.03 |
| hightemperature | night | 0.20 | 8.58 | 8.59 | 0.20 | 1501 | 0.01 | 0.01 |
ggplot(H2Ochemdf, aes(treatment, actualDOmg)) +
geom_jitter(color = "grey") +
geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
geom_point(data = H2Ochemdf.daynight.actualDO.summary, aes(x=treatment, y=mean), size=5, color = "purple") +
geom_errorbar(data =H2Ochemdf.daynight.actualDO.summary,
aes(x=treatment, y=mean, ymin = mean-sd, ymax = mean+sd),
color = "blue") +
geom_errorbar(data = H2Ochemdf.daynight.actualDO.summary,
aes(x=treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
colour = "red") +
facet_wrap(~period) +
geom_jitter(data = dn.DO.insitu, aes(treatment, actualDOmg),
color = "black") +
ggtitle("All Treatments, Actual Dissolved Oxygen (mg) Across Periods") +
theme_bw()## Warning: Removed 3 rows containing missing values (geom_point).
## [1] 18273 21
H2Ochemdf.daynight.pH.summary <- H2Ochemdf %>% group_by(treatment, period) %>%
summarize(sd = sd(pH, na.rm = TRUE),
mean = mean(pH, na.rm = TRUE),
median = median(pH, na.rm = TRUE),
IQR = IQR(pH, na.rm = TRUE),
n = n(), .groups= "drop_last") %>%
mutate(se = sd/sqrt(n)) %>%
mutate(ci = se*1.96)
write.csv(H2Ochemdf.daynight.pH.summary, "2020.10.26_H2Ochemdf_daynight_pH_summary.csv")
kable(H2Ochemdf.daynight.pH.summary, digits=2)| treatment | period | sd | mean | median | IQR | n | se | ci |
|---|---|---|---|---|---|---|---|---|
| allchange | D2Nramp | 0.02 | 7.57 | 7.57 | 0.03 | 166 | 0 | 0.00 |
| allchange | day | 0.03 | 7.53 | 7.53 | 0.03 | 4802 | 0 | 0.00 |
| allchange | night | 0.02 | 7.56 | 7.56 | 0.03 | 2842 | 0 | 0.00 |
| current | D2Nramp | 0.03 | 7.71 | 7.72 | 0.03 | 135 | 0 | 0.01 |
| current | day | 0.04 | 7.66 | 7.65 | 0.03 | 3849 | 0 | 0.00 |
| current | night | 0.04 | 7.70 | 7.72 | 0.03 | 2285 | 0 | 0.00 |
| hightemperature | D2Nramp | 0.02 | 7.72 | 7.72 | 0.02 | 86 | 0 | 0.00 |
| hightemperature | day | 0.03 | 7.66 | 7.66 | 0.03 | 2607 | 0 | 0.00 |
| hightemperature | night | 0.02 | 7.72 | 7.73 | 0.02 | 1501 | 0 | 0.00 |
ggplot(H2Ochemdf, aes(treatment, pH)) +
geom_jitter(color = "grey") +
geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
geom_point(data = H2Ochemdf.daynight.pH.summary, aes(x=treatment, y=mean), size=5, color = "purple") +
geom_errorbar(data =H2Ochemdf.daynight.pH.summary,
aes(x=treatment, y=mean, ymin = mean-sd, ymax = mean+sd),
color = "blue") +
geom_errorbar(data = H2Ochemdf.daynight.pH.summary,
aes(x=treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
colour = "red") +
geom_jitter(data = spec.insitu, aes(treatment, pH),
color = "black") +
facet_wrap(~period) +
ggtitle("All Treatments, Water Chemistry pH, Across Periods") +
theme_bw()## Warning: Removed 10 rows containing missing values (geom_point).
.**************END*************# .********************************* .# END OF SCRIPT | END OF DOCUMENT .*********************************
. ___________________8888, . ____________________Y8888b, . ___________________,oA8888888b, . _____________,aaad8888888888888888bo, . __________,d888888888888888888888888888b, . ________,888888888888888888888888888888888b, . _______d8888888888888888888888888888888888888, . ______d888888888888888888888888888888888888888b . _____d888888Pā Y888888888888, . _____88888P' Ybaaaa8888888888l . ___a8888'Y8888Pā V888888 . __d8888888aY8888 . AY/āā \Y8b ``Y8b . Y'YP ~~